package com.yxy.controller;

import com.yxy.base.BusinessException;
import com.yxy.base.Pagingable;
import com.yxy.base.RestResponse;
import com.yxy.dto.TableReceptionDto;
import com.yxy.service.TableReceptionService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.text.ParseException;

/**
 * @author huangxinrong
 *  预约管理
 */
@RestController
@Slf4j
@RequestMapping("/tableReception")//必须要加
public class TableReceptionController {

  @Autowired
  private TableReceptionService tableReceptionService;

  // 获取商品列表
  @Pagingable//添加分页
  @PostMapping("/list")
  public RestResponse getList(@RequestBody TableReceptionDto pojo) throws BusinessException {
    RestResponse restResponse = new RestResponse(200, "成功");
    restResponse.setContent(tableReceptionService.getlist(pojo));
    return restResponse;
  }

  // 获取商品列表
  @PostMapping("/getReservationsDayList")
  public RestResponse getReservationsDayList(@RequestBody TableReceptionDto pojo) throws BusinessException {
    RestResponse restResponse = new RestResponse(200, "成功");
    restResponse.setContent(tableReceptionService.getReservationsDayList(pojo));
    return restResponse;
  }

  // 获取商品列表
  @PostMapping("/getReservationsOverList")
  public RestResponse getReservationsOverList(@RequestBody TableReceptionDto pojo) throws BusinessException {
    RestResponse restResponse = new RestResponse(200, "成功");
    restResponse.setContent(tableReceptionService.getReservationsOverList(pojo));
    return restResponse;
  }


  // 获取商品列表
  @Pagingable//添加分页
  @PostMapping("/getListReceptionOutcome1")
  public RestResponse getListReceptionOutcome1(@RequestBody TableReceptionDto pojo) throws BusinessException {
    RestResponse restResponse = new RestResponse(200, "成功");
    restResponse.setContent(tableReceptionService.getListReceptionOutcome1(pojo));
    return restResponse;
  }



  //
  @PostMapping("/listByDay")
  public RestResponse getListByDay(@RequestBody TableReceptionDto pojo) throws BusinessException {
    RestResponse restResponse = new RestResponse(200, "成功");
    restResponse.setContent(tableReceptionService.getListByDay(pojo));
    return restResponse;
  }



  @PostMapping("/appGetReception")
  public RestResponse appGetReception(@RequestBody TableReceptionDto pojo) throws BusinessException {
    RestResponse restResponse = new RestResponse(200, "成功");
    restResponse.setContent(tableReceptionService.appGetReception(pojo));
    return restResponse;
  }



  //修改商品类型信息
  @PostMapping("/update")
  public RestResponse update(@RequestBody @Valid  TableReceptionDto pojo) throws BusinessException {
    RestResponse restResponse = new RestResponse(200, "成功");
    restResponse.setContent(tableReceptionService.modify(pojo));
    return restResponse;
  }


  @PostMapping("/receptionPass")
  public RestResponse receptionPass(@RequestBody @Valid  TableReceptionDto pojo) throws BusinessException {
    RestResponse restResponse = new RestResponse(200, "成功");
    restResponse.setContent(tableReceptionService.receptionPass(pojo));
    return restResponse;
  }

  @PostMapping("/workDayPass")
  public RestResponse workDayPass(@RequestBody @Valid  TableReceptionDto pojo) throws BusinessException {
    RestResponse restResponse = new RestResponse(200, "成功");
    restResponse.setContent(tableReceptionService.workDayPass(pojo));
    return restResponse;
  }

  @PostMapping("/workNoPass")
  public RestResponse workNoPass(@RequestBody @Valid  TableReceptionDto pojo) throws BusinessException {
    RestResponse restResponse = new RestResponse(200, "成功");
    restResponse.setContent(tableReceptionService.workNoPass(pojo));
    return restResponse;
  }

  @PostMapping("/receptionNoPass")
  public RestResponse receptionNoPass(@RequestBody @Valid  TableReceptionDto pojo) throws BusinessException {
    RestResponse restResponse = new RestResponse(200, "成功");
    restResponse.setContent(tableReceptionService.receptionNoPass(pojo));
    return restResponse;
  }

  //新增商品类型信息
  @PostMapping("/create")
  public RestResponse create(@RequestBody @Valid  TableReceptionDto pojo) throws BusinessException {
    RestResponse restResponse = new RestResponse(200, "成功");
    restResponse.setContent(tableReceptionService.save(pojo));
    return restResponse;
  }


  //app新增预约
  @PostMapping("/appCreate")
  public RestResponse appCreate(@RequestBody @Valid  TableReceptionDto pojo) throws BusinessException {
    RestResponse restResponse = new RestResponse(200, "成功");
    restResponse.setContent(tableReceptionService.appSave(pojo));
    return restResponse;
  }



  //app根据时间获取医师已经预约出去的号码
  @PostMapping("/appGetPhysicianTimeOver")
  public RestResponse appGetPhysicianTimeOver(@RequestBody @Valid  TableReceptionDto pojo) throws BusinessException {
    RestResponse restResponse = new RestResponse(200, "成功");
    restResponse.setContent(tableReceptionService.appGetPhysicianTimeOver(pojo));
    return restResponse;
  }



  @PostMapping("/checkPhysicianTime")
  public RestResponse checkPhysicianTime(@RequestBody @Valid  TableReceptionDto pojo) throws BusinessException {
    RestResponse restResponse = new RestResponse(200, "成功");
    restResponse.setContent(tableReceptionService.checkPhysicianTime(pojo));
    return restResponse;
  }



  //根据id删除商品类型信息
  @PostMapping("/delete")
  public RestResponse delete(@RequestBody @Valid TableReceptionDto pojo) throws BusinessException {
    RestResponse restResponse = new RestResponse(200, "成功");
    restResponse.setContent(tableReceptionService.delete(pojo.getId().toString()));
    return restResponse;
  }

    //每日预约量
    @PostMapping("/reservationNumber")
    public RestResponse reservationNumber(@RequestBody TableReceptionDto pojo) throws BusinessException, ParseException {
        RestResponse restResponse = new RestResponse(200, "成功");
        restResponse.setContent(tableReceptionService.reservationNumber(pojo));
        return restResponse;
    }

    //用户进行退号操作
    @PostMapping("/appRebackReceptionDetail")
    public RestResponse appRebackReceptionDetail(@RequestBody TableReceptionDto pojo) throws BusinessException, ParseException {
        RestResponse restResponse = new RestResponse(200, "成功");
        restResponse.setContent(tableReceptionService.appRebackReceptionDetail(pojo.getId().toString()));
        return restResponse;
    }
}
